-
Notifications
You must be signed in to change notification settings - Fork 395
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: PoC of inter-realm spec #2958
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is 📢 Thoughts on this report? Let us know! |
(The "review team" label was added by mistake. This PR is opened by a core dev.) |
@@ -341,7 +341,7 @@ func main() { | |||
// "Base": { | |||
// "@type": "/gno.RefValue", | |||
// "Escaped": true, | |||
// "ObjectID": "336074805fc853987abe6f7fe3ad97a6a6f3077a:2" | |||
// "ObjectID": "purePkg:336074805fc853987abe6f7fe3ad97a6a6f3077a:2" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for object from pure package, make objectID with a prefix "purePkg", so it's possible to distinct with object from realm. this does not change the current realm object persistence. but it looks ugly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thehowl any idea for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe r:xxx
and p:xxx
is good.
// PKGPATH: gno.land/r/crossrealm_test | ||
package crossrealm_test | ||
|
||
import ( | ||
crossrealm "gno.land/r/demo/tests/crossrealm" | ||
) | ||
|
||
type container struct { | ||
name string | ||
f *fooer | ||
} | ||
|
||
func (container) Foo() { println("hello " + c.f.name) } | ||
|
||
type fooer struct{ name string } | ||
|
||
var c = &container{name: "local_container"} | ||
|
||
func main() { | ||
ff := &fooer{name: "local_foo"} | ||
c.f = ff | ||
crossrealm.SetFooer(c) | ||
crossrealm.CallFooerFoo() | ||
print(".") | ||
} | ||
|
||
// Output: | ||
// hello local_foo | ||
// . | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc: @moul
// PKGPATH: gno.land/r/crossrealm_test | ||
package crossrealm_test | ||
|
||
import ( | ||
crossrealm "gno.land/r/demo/tests/crossrealm/func" | ||
) | ||
|
||
var b = 1 | ||
|
||
type Local_S struct { | ||
name string | ||
} | ||
|
||
func main() { | ||
f := func() bool { | ||
c := b | ||
var ls Local_S | ||
return true | ||
} | ||
crossrealm.SetCallback(f) | ||
println("ok") | ||
} | ||
|
||
// Output: | ||
// ok | ||
|
||
// Realm: | ||
// switchrealm["gno.land/r/demo/tests/crossrealm/func"] | ||
// switchrealm["gno.land/r/crossrealm_test"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please see this discussion about FuncValue
association .
#2958 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've spent most of today looking through realm.go and ownership.go so I could understand how they worked; I made a commit adding a bunch of comments which I hope are useful to whoever tries to understand it next.
I made some preliminary comments; I'll need another pass to be critical and proactive about different approaches / solutions.
gnovm/pkg/gnolang/ownership.go
Outdated
// realm where object is from | ||
originRealm PkgID |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if we used a *PackageValue
here instead? Could it not avoid us having to put whether it's a pure package in the PkgID?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also this is a bit weird, because "from" makes it sound like it's about where it's declared; while really it's the type's package where possible. Could you also update it?
I can also try to make a better comment on these if you prefer, but if you make a first pass I think it's better ;)
gnovm/pkg/gnolang/ownership.go
Outdated
// realm where object is from | ||
originRealm PkgID | ||
|
||
// if this object is attaching as a base of reference |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would appreciate a better comment here, not quite clear what this is for. Can you write an example?
gnovm/pkg/gnolang/realm.go
Outdated
@@ -220,9 +264,127 @@ func (rlm *Realm) DidUpdate(po, xo, co Object) { | |||
} | |||
} | |||
|
|||
// checkCrossRealm2 checks cross realm recursively. | |||
func checkCrossRealm2(rlm *Realm, store Store, tv *TypedValue, isLastRef bool, seenObjs []Object) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we have tests checking for some kinds of circular references?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, was meant to be just a "comment". Putting request changes for now.
1a6f3b9
to
49eb014
Compare
// PKGPATH: gno.land/r/crossrealm_test | ||
package crossrealm_test | ||
|
||
import ( | ||
crossrealm "gno.land/r/demo/tests/crossrealm/array" | ||
) | ||
|
||
var root interface{} | ||
|
||
func main() { | ||
root = crossrealm.GetArray5() | ||
println(".") | ||
} | ||
|
||
// Output: | ||
// . | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this works even the result of GetArray5()
is already real. the value is copied to current realm, and it's not bound to external realm, because its Type is not a declared type bound to the external realm.
address: the inter realm spec part from #2743.
Please refer to the original doc, and #2743 (comment)
And please see the comments below for details of implementation .
Contributors' checklist...
BREAKING CHANGE: xxx
message was included in the description